//
//  Community.swift
//  Sidekick
//
//  Created by John Bean on 11/10/25.
//

import Foundation

/// A hierarchical community of related entities in the knowledge graph
public struct Community: Identifiable, Codable, Hashable, Sendable {
	
	/// Stored property for `Identifiable` conformance
	public var id: UUID = UUID()
	
	/// The hierarchical level (0 = leaf/most specific, higher = more abstract)
	public var level: Int
	
	/// Array of entity IDs that belong to this community
	public var memberEntityIds: [UUID]
	
	/// Array of sub-community IDs (for hierarchical structure)
	public var subCommunityIds: [UUID]
	
	/// Summary text describing the community (generated by LLM)
	public var summary: String
	
	/// The embedding vector for the community summary
	public var embedding: [Float]?
	
	/// Title of the community (short descriptive name)
	public var title: String
	
	/// Initializer
	init(
		id: UUID = UUID(),
		level: Int,
		memberEntityIds: [UUID] = [],
		subCommunityIds: [UUID] = [],
		summary: String = "",
		embedding: [Float]? = nil,
		title: String = "Untitled Community"
	) {
		self.id = id
		self.level = max(level, 0) // Ensure non-negative
		self.memberEntityIds = memberEntityIds
		self.subCommunityIds = subCommunityIds
		self.summary = summary
		self.embedding = embedding
		self.title = title
	}
	
	/// Stub for `Equatable` conformance
	public static func == (lhs: Community, rhs: Community) -> Bool {
		lhs.id == rhs.id
	}
	
	/// Hash function for `Hashable` conformance
	public func hash(into hasher: inout Hasher) {
		hasher.combine(id)
	}
}

